package com.yanqu.road.server.cmd.activity.peakstronghold;

import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakStrongholdWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.*;

//@Cmd(code = CrossProtocol.C3_PEAK_STRONGHOLD_GET_UNION_REQ, desc = "")
@Deprecated
public class Cross3PeakStrongHoldGetUnionReqCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        PeakStrongholdWarProto.CrossPeakHoldGetUnionReqMsg reqMsg = PeakStrongholdWarProto.CrossPeakHoldGetUnionReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        List<String> unionUidList = reqMsg.getUnionIdList();
        if (unionUidList.size() == 0) {
            return;
        }
        // 返回值
        PeakStrongholdWarProto.CrossPeakHoldGetUnionRespMsg.Builder builder = PeakStrongholdWarProto.CrossPeakHoldGetUnionRespMsg.newBuilder();
        //来更新商会的
        builder.setActivityId(activityId);
        for (String s : unionUidList) {
            CrossUnionInfo unionInfo = CrossUnionMgr.getUnionInfo(s);
            Map<Long, CrossUnionMember> unionMemberMap = CrossUnionMgr.getUnionMemberMap(s);
            if (unionInfo != null && unionMemberMap != null) {
                PeakStrongholdWarProto.PeakStrongHoldUnionMsg.Builder tmp = PeakStrongholdWarProto.PeakStrongHoldUnionMsg.newBuilder();
                tmp.setUnionUid(s);
                tmp.setUnionInfo(UnionBasePb.parseUnionBaseTempMsg(CrossUnionMgr.parseUnionBaseInfo(unionInfo)));
                for (CrossUnionMember member : unionMemberMap.values()) {
                    tmp.addMember(PeakStrongholdWarProto.PeakStrongHoldUnionMemberMsg.newBuilder()
                            .setUserId(member.getUserId())
                            .setServerId(member.getServerId())
                            .setPosition(member.getPosition())
                            .setEarnSpeed(member.getUserBaseInfo().getEarnSpeed().toString())
                    );
                }
                builder.addUnion(tmp);
            }
        }
        builder.setUnionGroup(reqMsg.getUnionGroup());
        // 返回
//        MessageHelper.sendPacket(serverId, 0, YanQuMessageUtils.buildMessage(CrossProtocol.C_PEAK_STRONGHOLD_GET_UNION_RESP, builder));
//        MessageHelper.sendUnionActivityGroupPacket(serverId, 0, CrossProtocol.C_PEAK_STRONGHOLD_GET_UNION_RESP, builder, activityId, 0, reqMsg.getUnionGroup());
    }

    @Override
    public void sendData() {

    }

}
